import java.util.Scanner;
import java.util.Random;
import java.util.Arrays;
public class Test {
    public static void main(String[] args){
//        System.out.println("hell0");
        //func1();
//        System.out.println(func2());
//        func3();
//        func4(123);
//        System.out.println(max1(2,3,4));
//        System.out.println(fib(4));
        int[]arr={2,7,11,15};
//        func5(arr);
//        func6(arr);
        int[]arr3=func7(arr,9);
        System.out.println(Arrays.toString(arr3));
//        System.out.println(Arrays.toString(arr));
    }
//    猜数字游戏
    public static void func1(){
        Random random=new Random();
        Scanner scanner=new Scanner(System.in);
        int toGuess=random.nextInt(100);
        while(true){
            System.out.println("请输入要猜的数字（在1-100）：");
            int num =scanner.nextInt();
            if(num==toGuess){
                System.out.println("恭喜你才对了");
                break;
            }else if(num<toGuess){
                System.out.println("猜小了");
            }else{
                System.out.println("猜大了");
            }
        }
        scanner.close();
    }
//    计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值
    public static double func2(){
        int flg=1;
        double sum=0;
        for(int i=1;i<=100;i++){
            sum+=flg*(1.0/i);
            flg=-flg;
        }
        return sum;
    }
    public static void func3(){
        Scanner sc=new Scanner(System.in);
        String password="123456";
        int i=0;
        while(i<3){
            System.out.println("请输入密码");
            String str= sc.next();
            if((password.equals(str))==true){
                System.out.println("登陆成功");
                break;
            }else{
                System.out.println("密码错误,请重新输入，您有三次机会：");
            }
        }
    }
    public static void func4(int n){
        if(n<10){
            System.out.println(n);
        }
        if(n>=10){
            while(n!=0){
                System.out.println(n%10);
                n=n/10;
        }
        }
    }
    public static int max2(int a,int b){
        if(a>b){
            return a;
        }else {
            return b;
        }
    }
    public static int max1(int a,int b,int c){
        int num_max=max2(a,b);
        int num_max2=max2(b,c);
        if(num_max2>num_max){
            return num_max2;
        }else{
            return num_max;
        }
    }
    public static int fib(int m){
        if(m==1||m==2){
            return 1;
        }else{
            return fib(m-1)+fib(m-2);
        }
    }
    public static int[] func5(int [] arr){
        for(int i=0;i<arr.length;i++){
            arr[i]=arr[i]*2;
        }
        return  arr;
    }
    public static int[] func6(int[] arr){
        int count=0;
        int count2=0;
        int[]arr1=new int[arr.length];
        int[]arr2=new int[arr.length];
        for(int i=0;i< arr.length;i++) {
            if (arr[i] % 2 != 0) {
                arr1[count] = arr[i];
                count += 1;
            }else {
                arr2[count2]=arr[i];
                count2+=1;
            }
        }
        for (int i = 0; i <count ; i++) {
//           arr[i]=arr1[i];
            System.out.println(arr1[i]);
            arr[i]=arr1[i];
        }
        for (int i = 0; i < count2; i++) {
//            arr[count]=arr2[i];
            System.out.println(arr2[i]);
            arr[count]=arr2[i];
            count++;
        }
        return arr;
    }
    public static int[]func7(int []arr,int n){
        int[]arr1=new int[2];
        for (int i = 0; i < arr.length ; i++) {
            for (int j = 0; j < arr.length; j++) {
                if(arr[i]+arr[j]==n){
                    arr1[0]=i;
                    arr1[1]=j;
                    break;
                }
            }
        }
        return arr1;
    }
}
